import { getToken, setToken, removeToken } from '@/utils/auth'
import { login } from '@/api/user.js'
export default {
  namespaced: true,
  state: {
    token: '' || getToken()
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
      // 数据存储到本地token中
      setToken(token)
    },
    removeToken(state) {
      state.token = ''
      // 删除本地token
      removeToken()
    }
  },
  actions: {
    async postLogin(context, payload) {
      const res = await login(payload)
      context.commit('updateToken', res.data)
    }
  }
}

